function [dist_s, dist_d, d_grid] = build_distributions(muS,sigS,s_min,s_max,muD,sigD,d_min,d_max,d_spc,optfig,fig)

% Distribution of aggregate shocks (s)

dist_s = makedist('Lognormal','mu',muS,'sigma',sigS);
dist_s = truncate(dist_s,s_min,s_max);
s_spc = 0.001;

s_grid = (s_min:s_spc:s_max)';
s_pdf  = pdf(dist_s,s_grid);
s_cdf  = cdf(dist_s,s_grid);

% Distribution of deposits

dist_d = makedist('Lognormal','mu',muD,'sigma',sigD);
dist_d = truncate(dist_d,d_min,d_max); % It is important to truncate here (otherwise integral uppper limit = Inf)

d_grid = (d_min:d_spc:d_max)';
d_pdf  = pdf(dist_d,d_grid);
d_cdf  = cdf(dist_d,d_grid);

%% Figures
if fig == 1
    
    fig_distrib(s_grid, s_pdf, s_cdf, optfig, 's')
    fig_distrib(d_grid, d_pdf, d_cdf, optfig, 'D_{0}(i)')
    
    if max(d_cdf)~=1; disp(max(d_cdf)); disp('increase d_max'); end
end

end